package com.yuantutech.pay.bootstrap;

import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;

/**
 * Service Bootstrap
 */
public class DubboBootstrap {

	private static Logger logger = LoggerFactory
			.getLogger(DubboBootstrap.class);
	public static AbstractXmlApplicationContext context = null;

	/**
	 * 启动入口
	 */
	public static void main(String[] args) {

		try {
			logger.warn("starting...");
			context = new ClassPathXmlApplicationContext(
					"classpath:config/applicationContext*.xml");
			if (context != null) {
				context.start();
				logger.warn("service started successfully.");
				System.in.read(); // press any key to exit
			}
		} catch (Exception e) {
			logger.error("init error", e);
			if (context != null) {
				logger.info("context close.");
				context.close();
				context = null;
			}
		}
	}

	/*static {
		Runtime runtime = Runtime.getRuntime();
		runtime.addShutdownHook(new Thread() {
			@Override
			public void run() {
				if (context != null) {
					logger.info("context close.");
					context.close();
					context = null;
				}
			}
		});
	}*/
}
